home *** CD-ROM | disk | FTP | other *** search
- ;-------------------------bcdout routine begins--------------------------+
- ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
- ; page : 66
- ;
- ; NAME BCDOUT
- ; ROUTINE FOR conversion from BCD to ASCII decimal
- ;
- ; FUNCTION: This routine converts a 36-digit number sstored in BCD form
- ; to ASCII decimal form which is sent to the std I/O device.
- ;
- ; INPUT: Upon entry a 36-digit number is stored in an 18-byte BCD buffer
- ; called BCDBUFF in the DATAS data segment.
- ;
- ; OUTPUT: A string of ASCII digits representing a decimal number is
- ; stored in a buffer called TBUFF and then sent out through a standard
- ; output device.
- ;
- ; REGISTERS USED: No registers are modified.
- ; SEGMENTS REFERENCED: DATAS is a data segment containing BCDBUFF
- ; and TBUFF.
- ;
- ; ROUTINES CALLED: STDOUT
- ; SPECIAL NOTES: None
- ;
- ; ROUTINE FOR CONVERSION FROM BCD TO ASCII DECIMAL
- ;
- bcdout proc far
- ;
- push ds ; save registers
- push si
- push dx
- push cx
- push ax
- ;
- ; set up a data segment
- mov ax,datas ; point to data segment
- mov ds,ax
- ;
- mov cx,18 ; for a count of 18
- lea si,bcdbuff ; point to bcd buffer
- add si,17 ; point to end of bcd buffer
- mov dh,0 ; clear flag for leading zeros
- ;
- bdcout1:
- push cx ; save count
- mov al,[si] ; get BCD byte
- dec si ; and point to next
- mov dl,al ; save it
- ;
- ; upper digit
- mov cl,4 ; for a count of four
- rol al,cl ; rotate byte
- and al,0Fh ; just the digit
- or dh,al ; leading zeros?
- jz bcdout2 ; if so skip digit
- add al,30h ; make it ASCII
- call stdout ; send it
- ;
- bcdout2:
- pop cx ; restore count
- cmp cx,1 ; last digit ?
- jnz bcdout3 ; skip if not
- mov dh,0FFh ; set flag if so
- ;
- bcdout3:
- push cx ; save count
- ;
- mov al,dl ; get byte back
- ;
- ; lower digit
- and al,0Fh ; just the digit
- or dh,al ; leading zeros?
- jz bcdout4 ; if so skip digit
- add al,30h ; make is ASCII
- call stdout ; send it
- ;
- bcdout4:
- ;
- pop cx ; restore loop count
- loop bcdout1
- ;
- pop ax ; restore registers
- pop cx
- pop dx
- pop si
- pop ds
- ret ; return
- ;
- bcdout endp
- ;-------------------------bcdout routine ends---------------------------+